package com.yz.jdd.module.cashier;

import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.yz.jdd.R;
import com.yz.jdd.base.activity.BaseActivity;

/**
 * 收银订单备注
 * xiongzhuang
 * 2019-10-18
 */
public class CashierRemarkActivity extends BaseActivity implements View.OnClickListener {

    private ImageView back_nav;
    private TextView title_nav;
    private EditText edit_remark;
    private Button btn_enter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_cashier_remark);
        findViewById();
        String remark = getIntent().getStringExtra("remark");
        if(!TextUtils.isEmpty(remark)){
            edit_remark.setText(remark);
            edit_remark.setSelection(remark.length());
        }
    }

    private void findViewById() {
        back_nav = findViewById(R.id.back_nav);
        back_nav.setOnClickListener(this);
        title_nav = findViewById(R.id.title_nav);
        title_nav.setText("备注信息");
        edit_remark = findViewById(R.id.edit_remark);
        edit_remark.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                if (s.toString().length() >= 20) {
                    Toast.makeText(CashierRemarkActivity.this, "最多输入20个字", Toast.LENGTH_SHORT).show();
                }
            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });
        btn_enter = findViewById(R.id.btn_enter);
        btn_enter.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.back_nav:
                finish();
                break;
            case R.id.btn_enter:
                String remark = edit_remark.getText().toString();
//                if (TextUtils.isEmpty(remark)) {
//                    Toast.makeText(this, "请输入备注信息", Toast.LENGTH_SHORT).show();
//                } else {
                    Intent intent = new Intent();
                    intent.putExtra("remark",remark);
                    setResult(30,intent);
                    finish();
//                }
                break;
            default:
                break;
        }
    }
}
